package com.example.tests;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select ;
import com.example.pages.InternalPage;
import com.example.pages.LoginPage;
import com.example.pages.Page;
import com.example.pages.UsersPage;

public class CreatNewUserTest {
private static WebDriver driver;
  private String baseUrl;
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();




  @Before
  public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "http://localhost/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
 public void creatNew () throws Exception {  
    goToMainPage();
    vxod("admin", "admin");
}

  
private void goToMainPage() {
	driver.get(baseUrl + "/php4dvd/");
	LoginPage loginPage = PageFactory.initElements(driver, LoginPage.class);
}

public static void  vxod(String password, String username){
	LoginPage.userNameField.clear();
	LoginPage.userNameField.sendKeys(username);
	LoginPage.passwordField.clear();
	LoginPage.passwordField.sendKeys(password);
	LoginPage.LoginButton.click();
	
}


  @After
  public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }

  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alert.getText();
    } finally {
      acceptNextAlert = true;
    }
  }
}
